import java.util.ArrayList;
import java.util.List;

public class ReBinaryTreeDemo {
    public static void main(String[] args) {
        TreeNode head = BinaryTree.randomTree(7);
        List<Integer> preOrder = new ArrayList<>();
        List<Integer> inOrder = new ArrayList<>();
        BinaryTree.show(head);
        pre(head, preOrder);
        in(head, inOrder);
        System.out.println("pre: " + preOrder);
        System.out.println("in: " + inOrder);
        BinaryTree.show(
                BinaryTree.re(
                        preOrder.stream().mapToInt(Integer::intValue).toArray(),
                        inOrder.stream().mapToInt(Integer::intValue).toArray()
                )
        );
    }

    public static void pre(TreeNode head, List<Integer> preOrder) {
        if (head == null) return;
        preOrder.add(head.val);
        pre(head.left, preOrder);
        pre(head.right, preOrder);
    }

    public static void in(TreeNode head, List<Integer> inOrder) {
        if (head == null) return;
        in(head.left, inOrder);
        inOrder.add(head.val);
        in(head.right, inOrder);
    }
}